// pages/past/past.ts
interface ThemeData {
  title: string,
  firstBrief: string,
  secondBrief: string,
  startTime: string,
  endTime: string,
  imgUrl: string,
}
interface ThemeDataArray {
  [index: number]: ThemeData;
}

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShowMore: false,
    themeData: [] as ThemeDataArray,
    gradeData: [
      { id: 0, name: "全部" },
      { id: 1, name: "初一" },
      { id: 2, name: "初二" },
      { id: 3, name: "初三" },
    ],
    classData: [
      { id: 0, name: "全部" },
      { id: 1, name: "（1）班" },
      { id: 2, name: "（2）班" },
      { id: 3, name: "（3）班" },
      { id: 4, name: "（4）班" },
    ],
    subjectData: [
      { id: 0, name: "全部" },
      { id: 1, name: "物理" },
      { id: 2, name: "化学" },
    ],
  },
  goToPast() {

  },
  handleMore() {
    this.setData({
      isShowMore: !this.data.isShowMore
    })
  },
  handleSubmit(e: any) {
    const { grade, class: classroom, subject } = e.detail;
    wx.request({
      url: "https://mock.presstime.cn/mock/656dbe322fef936d34630d40/yi-xiao-ping/past-theme",
      data: {
        grade,
        classroom,
        subject
      },
      success: (res: {
        data: {
          data: ThemeDataArray;
          code: number;
        }
      }) => {
        const { data } = res;
        const { code, data: themeData } = data;
        if (code === 200) {
          this.setData({
            themeData: themeData,
            isShowMore: false,
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    wx.request({
      url: "https://mock.presstime.cn/mock/656dbe322fef936d34630d40/yi-xiao-ping/past-theme",
      success: (res: {
        data: {
          data: ThemeDataArray;
          code: number;
        }
      }) => {
        const { data } = res;
        const { code, data: themeData } = data;
        if (code === 200) {
          this.setData({
            themeData: themeData,
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})